@layout("/common/_container.html",{js:["/assets/modular/system/project/project_queuing.js"]}){
<meta charset='utf-8'>
<style>
    .input {
        border: none;
        width: 153px;
    }
    .layui-table tbody tr:hover,
    .layui-table thead tr,
    .layui-table-click,
    .layui-table-header,
    .layui-table-hover,
    .layui-table-mend,
    .layui-table-patch, .layui-table-tool,
    .layui-table-total, .layui-table-total tr, .layui-table[lay-even] tr:nth-child(even) {
        background-color: #FFFFFF;
    }

    td {
        white-space: nowrap;
    }
    .pzhu{
        color: red;
    }
</style>
</head>
<body>
    <input hidden id="qb" value="${qb}">
    <table class="layui-table" style="width: 90%;margin-left: 20px;" id="tables">
        <thead>
        <tr>
            <td>美团门店ID</td>
            <td>商米V2 PRO</td>
            <td>T2一体机</td>
            <td>蓝牙音箱</td>
            <td>电视盒子</td>
            <td>收件人</td>
            <td>收件人电话</td>
            <td>收件地址</td>
            <td>其他说明</td>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td><input class="input" id="mt" autocomplete="off"/></td>
            <td><input class="input" id="smi" autocomplete="off"/></td>
            <td><input class="input" id="ytj" autocomplete="off"/></td>
            <td><input class="input" id="lyyx" autocomplete="off"/></td>
            <td><input class="input" id="dshz" autocomplete="off"/></td>
            <td><input class="input" id="sjr" autocomplete="off"/></td>
            <td><input class="input" id="sjdh" autocomplete="off"/></td>
            <td><input class="input" id="sjdz" autocomplete="off"/></td>
            <td><input class="input" id="qtsj" autocomplete="off"/></td>
        </tr>
        </tbody>
    </table>
<div class="layui-inline" style="margin-left: 10px;margin-top: 20px;margin-bottom: 20px">
    <button class="layui-btn icon-btn" onclick="table2excel()">下载
    </button>
    @if(shiro.hasPermission("/project/wsjdbc")){
    <button id="btnKeep" class="layui-btn icon-btn">保存
    </button>
    @}
    <button id="backupPage" class="layui-btn icon-btn">返回
    </button>
    @if(shiro.hasPermission("/project/wsjd")){
    <button id="audit" class="layui-btn icon-btn">状态
    </button>
    @}
<!--    <button id="add" class="layui-btn icon-btn">测试添加-->
<!--    </button>-->
</div>
<!--批注说明-->
<div style="margin-left: 20px">
    <p class="pzhu">说明：</p><br/>
    <p class="pzhu">①：设备可填写数量。商米V2 PRO和T2一体机最多二选一，同一设备数量不能多于一个，否则需填写充其他。</p><br/>
    <p class="pzhu">②：收件人信息如不填写，默认同美团门店信息。</p><br/>
    <p class="pzhu">③：收件地址一定要标注清楚xxx省xxx市xxx区xxx</p>
</div>
</body>
<script src="https://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="application/javascript">
    // 导出表格
    function table2excel() {
        $("#tables tr td").each(function (index, el) {
            if ($(this).find('input').length) {
                // 存在 input
                $(this).find('input').attr('value', $(this).find('input').val());
            }
        });
        $("#tables").table2excel({
            // 不被导出的表格行的CSS class类
            exclude: ".noExl",
            // 导出的Excel文档的名称
            name: "排队机",
            // Excel文件的名称
            filename: "排队机",
            //文件后缀名
            fileext: ".xls",
            //是否排除导出图片
            exclude_img: false,
            //是否排除导出超链接
            exclude_links: false,
            //是否排除导出输入框中的内容
            exclude_inputs: true
        });
    }


    // $('#add').click(function () {
    //     $('.input').val('测试')
    // });


    const id = '${id}';
    const role = '${role}';
    const content = '${content}';
    const lists = [${list}];

    $(function () {
        for (let i = 0; i < lists[0][0].length; i++) {
            let pinCode = lists[0][0][i].pinCode;
            $("#" + pinCode + "").val(lists[0][0][i].data);
            if (role != "2") {
                $("#" + pinCode + "").attr("readonly", true);
                $('#btnKeep').hide();
            }
            if (content == "1") {
                $('#audit').hide();
                $('#btnKeep').hide();
            }
        }
    });

    $('#btnKeep').click(function () {
        var list = [];
        for (let i = 1; i < 10; i++) {
            var object = {};
            if (i == 1) {
                object.proId = id;
                object.mouldId = "37";
                object.data = $("#mt").val();
                object.pinCode = "mt";
            } else if (i == 2) {
                object.data = $("#smi").val();
                object.pinCode = "smi";
            } else if (i == 3) {
                object.data = $("#ytj").val();
                object.pinCode = "ytj";
            } else if (i == 4) {
                object.data = $('#lyyx').val();
                object.pinCode = "lyyx";
            } else if (i == 5) {
                object.data = $('#dshz').val();
                object.pinCode = "dshz";
            } else if (i == 6) {
                object.data = $('#sjr').val();
                object.pinCode = "sjr";
            } else if (i == 7) {
                object.data = $('#sjdh').val();
                object.pinCode = "sjdh";
            } else if (i == 8) {
                object.data = $('#sjdz').val();
                object.pinCode = "sjdz";
            } else if (i == 9) {
                object.data = $('#qtsj').val();
                object.pinCode = "qtsj";
            }
            object.dataType = 1;
            object.sort = i;
            list.push(object);
        }
        $.ajax({
            type: "post",
            url: "/mouldBoardMsg/add",
            data: JSON.stringify(list),
            contentType: 'application/json',
            async: false,
            success: function (data) {
                list = [];
                layer.msg('保存成功！', {icon: 1},);
                window.location.href = Feng.ctxPath + '/task/steerTask?id=' + id;
            }
        });
    });

    // 审核
    $('#audit').click(function () {
        layer.open({
            area: ['300px', '150px'],
            title: '状态',
            btn: ['完成', '驳回'],
            btnAlign: 'c',
            type: 1,
            content: ' <div style="text-align:center;" id="div">\n' +
                ' <textarea type="text" hidden class="input" id="reason" placeholder="请填写驳回理由" style="height: 100px;width: 92%;margin-top: 10px;padding-left: 5px;"></textarea>\n' +
                ' </div>',
            yes: function (index, layero) {
                shenHe("1", "排队机已建完");
            },
            btn2: function (index, layero,) {
                $('.input').show();
                var reason = $('#reason').val();
                if (reason == '') {
                    $('.layui-layer-btn .layui-layer-btn0').hide();
                    $('.layui-layer-btn1').text('提交');
                    $('.layui-layer-btn1').css('background', '#1E9FFF');
                    $('.layui-layer-btn1').css('color', '#FFF');
                    layer.msg('请填写驳回理由！', {icon: 2},);
                    return false
                } else {
                    shenHe("0", reason);
                    layer.close(index);
                }
                // Project.shenHe(0, data.id);
                // layer.close(index);
            },
        })
    });

    function shenHe(data, reason) {
        let obj = {};
        obj.proId = id;
        obj.status = data;
        obj.taskId = "38";
        obj.content = reason;
        obj.taskName = "排队机";
        $.ajax({
            type: "post",
            url: "/task/audit",
            data: obj,
            async: false,
            success: function () {
                if (data == 1) {
                    layer.msg('已确认！');
                } else {
                    layer.msg('已驳回！');
                }
                parent.location.reload();
            }
        });
    }
</script>
@}